#pragma once

#include <QImage>
#include <vector>
#include <opencv2/opencv.hpp>
#include "HalconCpp.h"
//#include <math.h>

using namespace HalconCpp;

#include <QCoreApplication>
#include <QThread>

template<typename F>
void postToThread(F&& fun, QThread* thread = qApp->thread()) {
	    auto* obj = QAbstractEventDispatcher::instance(thread);
	    Q_ASSERT(obj);
	    QMetaObject::invokeMethod(obj, std::forward<F>(fun));
	}


// 定义常量PI值
const double pi = atan2(0, -1);

namespace Vision_API
{
	using cvContour = std::vector<cv::Point>;	// 轮廓
	using cvContourSet = std::vector<cvContour>;	// 轮廓集
	using polygonPoints = std::vector<cv::Point2f>;

	/// <summary>
	/// 图像类型转换：Halcon opencv qt三种常见数据结构的转换
	/// HImage cv::Mat QImage
	/// </summary>
	/// <param name="src"></param>
	/// <returns></returns>
	HImage HImageFromMat(cv::Mat& src);
	bool QImage2HImage(QImage& from, HalconCpp::HImage& to);
	bool HImage2QImage(HalconCpp::HImage& from, QImage& to);

	QImage mat2QImage(cv::Mat& mat);
	cv::Mat qImage2Mat(QImage& image);

	// 弧度与角度计算：halcon常用
	double rad2Deg(double rad);	
	double deg2Rad(double deg);

	// 简单绘制函数
	// 绘制“十”字点
	void drawCross(cv::Mat& src, cv::Point pt, cv::Scalar color = cv::Scalar(0, 0, 255), cv::Size sz = cv::Size(3, 3));
	void textOut(cv::Mat& src, cv::Point pt, cv::Scalar color = cv::Scalar(0, 0, 255));

	void drawHalconXld(cv::Mat& src, HXLDCont& xld, cv::Scalar color = cv::Scalar(0,0,255));
	void drawOpencvContour(cv::Mat& src, std::vector<polygonPoints>& allContours, cv::Scalar color=cv::Scalar(0,0,255));
}
